home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 193_01 / backup.c < prev    next >
Text File  |  1985-11-13  |  17KB  |  354 lines

  1. /*-----------------------------------------------------------------*/
  2. /*  PROGRAMME  ==>  backup.c                                       */
  3. /*  Will back up any files which don't have the archive bit        */
  4. /*  ( = t3) already set.                                           */
  5. /*  VERSION:  1.3       Written:  13th July, 1986                  */
  6. /*  -------             -------   Phil. E. Cogar                   */
  7. /*                                                                 */
  8. /*  Note: It uses an 8K buffer to do the file transfers            */
  9. /*  ----                                                           */
  10. /*  Usage is -                                                     */
  11. /*                 backup [d1] [d2]                                */
  12. /*                                                                 */
  13. /*  where, "d1" and "d2" are drive names.                          */
  14. /*                                                                 */
  15. /*  This programme uses the CP/M functions -                       */
  16. /*                                                                 */
  17. /*                 15   open file                                  */
  18. /*                 16   close file                                 */
  19. /*                 17   search first                               */
  20. /*                 18   search next                                */
  21. /*                 19   erase file                                 */
  22. /*                 26   set DMA address                            */
  23. /*                 30   set file attributes                        */
  24. /*  which will be found in the file DEFF3 and which will be added  */
  25. /*  automatically to the "COM" file when you use CLINK.            */
  26. /*                                                                 */
  27. /*  to do the required work.                                       */
  28. /*  Written by:         Phil Cogar - July 12, 1986                 */
  29. /*  ----------                                                     */
  30. /*  Copyright 1986 - Cogar Computer Services Pty.Ltd.              */
  31. /*-----------------------------------------------------------------*/
  32. #include <bdscio.h>    /* NOTE: This programme is specific to     */
  33.             /* ----  BDS 'C'.   If you use a different */
  34.             /*       C then you must change this line. */
  35. #include <pec.h>    /* Required for this file                  */
  36. /*-----------------------------------------------------------------*/
  37. #define SECTORS 64    /* To be used in 8K buffer, transfer_buf   */
  38. #define VERSION "1.3"    /* Current version number                  */
  39. char    transfer_buf[SECTORS*128]; /* which is for the copy part   */
  40.                    /* of the programme.            */
  41. /*-----------------------------------------------------------------*/
  42.  
  43. main(argc,argv)
  44. short argc;
  45. char *argv[];
  46. {
  47. /*  The defined values used in the programme                       */
  48. /*-----------------------------------------------------------------*/
  49.     char fcb[36];    /* Use for the ambiguous file mask         */
  50.     short drive1, drive2, d1, d2;    /* The nominated drives.   */
  51.     char name_buf[3200];    /* Use to hold the file names      */
  52.                     /* Note present limit of 100       */
  53.     char fcb1[36];    /* The file control blocks                 */
  54.     char fcb2[36];    /* used in the file_copy routine           */
  55.     char dma[128];    /* The DMA buffer for CP/M to use  */
  56.     char mode[4];    /* The file mode                           */
  57.         mode[0] = 'A';  /* I know it can be done more      */
  58.         mode[1] = 'R';  /* elegantly, but this makes it    */
  59.         mode[2] = 'C';    /* clear that mode = "ARC"         */
  60.         mode[3] = '\0';    /* with NULL terminator.           */
  61.     short count, file_count, i, j, k, n; /* counters             */
  62.     short value;        /* General purpose function return */
  63.     short offset;    /* Used in recovering the names from the   */
  64.             /* name_buf, where we store them.          */
  65.     short pointer;    /* Used in transferring data to-and-from   */
  66.             /* the transfer buffer.                    */
  67. /*-----------------------------------------------------------------*/
  68. /*  The programme proper starts here.                              */
  69. /*  First construct the ambiguous search mask  for use in the      */
  70. /*  CP/M "search first" and "search next" routines                 */
  71. /*-----------------------------------------------------------------*/
  72.  
  73.     fcb[0] = '\0';    /* Note: Drive not allocated yet           */
  74.     for(i = 1; i < 12; i++)
  75.         fcb[i] = '?';
  76.     for(i = 12; i < 36; i++)
  77.         fcb[i] = '\0';
  78.         
  79.     
  80.     offset = file_count = 0;    /* starting values         */
  81.  
  82.     pec_clear();    /* clear the screen to start */
  83.     sign_on();    /* and put sign-on message                 */
  84.  
  85. /*-----------------------------------------------------------------*/
  86. /*  Now set the DMA buffer for transfer of information to and from */
  87. /*  the nominated drives.   This buffer will be used throughout    */
  88. /*  the programme whenever a file is accessed.                     */
  89. /*-----------------------------------------------------------------*/
  90.  
  91.     set_dma(dma);
  92.     
  93. /*-----------------------------------------------------------------*/
  94. /*  The programme proper starts here.   First see whether the two  */
  95. /*  drive names have been  entered.                                */
  96. /*-----------------------------------------------------------------*/
  97.  
  98.     if(argc < 3)    /* check to see if both drive names given  */
  99.     {
  100.         drive1 = mess1(drive1); /* and if not then we have */
  101.         drive2 = mess2(drive2); /* to ask for them         */
  102.     }
  103.     else if(argc == 3)
  104.     {
  105.         drive1 = toupper(*argv[1]);
  106.         drive2 = toupper(*argv[2]);
  107.     }
  108.     else mess3(); /* Otherwise you've screwed up somehow.      */
  109.  
  110. /*-----------------------------------------------------------------*/
  111. /*  Now check to see whether valid drive names were entered.       */
  112. /*  This programme only recognises drives A, B, C and D.   If you  */
  113. /*  have other drives change "check_drive" to suit.                */
  114. /*-----------------------------------------------------------------*/
  115.  
  116.     check_drive(drive1);
  117.     check_drive(drive2);
  118.  
  119. /*-----------------------------------------------------------------*/
  120. /*  For the programme to work the drive names have to be different */
  121. /*  so now check that they are, else quit.                         */
  122. /*-----------------------------------------------------------------*/
  123.  
  124.     if(drive1 == drive2)
  125.         mess4();
  126.  
  127. /*-----------------------------------------------------------------*/
  128. /*  Now convert the drive names to CP/M format and use the search  */
  129. /*  first and search next functions to collect those names where   */
  130. /*  the t3 character doesn't have bit 7 set.   Save these names    */
  131. /*  into the name buffer                                           */
  132. /*-----------------------------------------------------------------*/
  133.  
  134.     d1 = drive1 - 'A' + 1;    /* Convert drives to CP/M format   */
  135.     d2 = drive2 - 'A' + 1;
  136.  
  137.     fcb[0] = d1;    /*  Put FROM drive into search mask then   */
  138.             /*  call the search first routine          */
  139.  
  140.     if((i = search_first(fcb)) != 255)
  141.     {
  142.         count = save_name(i, dma, name_buf, offset);
  143.         file_count = file_count + count;
  144.         if(count)
  145.             offset = offset + 32;
  146.     }
  147.     else mess5();
  148.  
  149.  
  150.     while((i = search_next()) != 255) /* Now do search next    */
  151.     {
  152.         count = save_name(i, dma, name_buf, offset);
  153.         file_count = file_count + count;
  154.         if(count)
  155.             offset = offset + 32;
  156.     }
  157.  
  158. /*-----------------------------------------------------------------*/
  159. /*  Now check the name buffer and see if any files were found to   */
  160. /*  copy.   If not then quit.                                      */
  161. /*-----------------------------------------------------------------*/
  162.  
  163.     if(file_count == 0)
  164.         mess6();
  165.  
  166. /*-----------------------------------------------------------------*/
  167. /*  If we get to here then there are some files to be archived so  */
  168. /*  we can now start to copy these across to the back-up drive.    */
  169. /*-----------------------------------------------------------------*/
  170.  
  171.     printf("\n\nStart of copying\n");
  172.     printf("----------------\n\n");
  173.  
  174.     offset = 0;    /*  SüÄü